define(function(require, exports, module) {

  var $ = require('jquery');
  var THREE = require('three');

  var env = window.env;
  var { scene, camera, renderer, mesh } = init();

  function main() {
    var $app = $('<div id="app">');
    $('#main').html($app);

    $app.append(renderer.domElement)
    step()
  }

  function init() {
    var scene = new THREE.Scene();
    var geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
    var material = new THREE.MeshNormalMaterial();
    var mesh = new THREE.Mesh(geometry, material);
    mesh.position.set(0,0.5,0.5)
    scene.add(mesh);


    var axesHelper = new THREE.AxesHelper( 0.5 );
    scene.add( axesHelper );

    var camera = new THREE.PerspectiveCamera(70, env.w / env.h, 0.01, 10);
    camera.position.x = 1;
    camera.position.y = 1;
    camera.position.z = 1;
    camera.lookAt(0,0,0)
    var renderer = new THREE.WebGLRenderer( { antialias: true } );
    renderer.setSize(env.w, env.h);

    return { scene, camera, renderer, mesh };
  }

  function step() {
    requestAnimationFrame(step);

    // mesh.rotation.x += 0.05;
    mesh.rotation.y += 0.02;

    renderer.render(scene, camera);
  }

  return main;
})
